from django.shortcuts import render
from django.http import HttpResponse
import json
import traceback
import urllib
import urllib.parse
import urllib.request
import requests
import tushare as ts
from sqlalchemy import create_engine

def hello(request):
    
    return HttpResponse("Welcome to coin world")

def vueapitest(request):
    ts.set_token("2aca6633c05b1a8d5ec094b0a275e95e1fcc3373d8a1524d25f0e003")
    pro = ts.pro_api()
#    pro.quert('coinbar',exchange='',symbol='',freq='')  
    return HttpResponse("123")

def init(request):
    engine = create_engine('mysql://root:@127.0.0.1/cointrade?charset=utf8')
    ts.set_token("2aca6633c05b1a8d5ec094b0a275e95e1fcc3373d8a1524d25f0e003")
    pro = ts.pro_api()
    #全球交易所信息
    df=pro.query('coinexchanges')
    df.to_sql('coin_exchanges',engine)
    #全球数字货币列表
    df=pro.query('coinlist',issue_date='')
    df.to_sql('coins',engine)

    # #全球交易所费率
    # df=pro.query('coinfees',exchange='huobi')
    # df.to_sql('coins',engine)

    return HttpResponse('db init success')